<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
 
// import Joomla controller library
jimport('joomla.application.component.controller');
jimport('joomla.filesystem.file');
 
/**
 * General Controller of AnJoLinA component
 */
class AnJoLinAController extends JController
{
	/**
	 * display task
	 *
	 * @return void
	 */
	function display($cachable = false) 
	{		
		// set default view if not set
		JRequest::setVar('view', JRequest::getCmd('view', 'selectcategories'));
 
		// call parent behavior
		parent::display($cachable);
	}
	
	public function mobile_publish()
	{
		$ids = JRequest::getVar('cid', array(), '', 'array');
		
		/* Ein Datenbankobjekt beziehen */
		$db = JFactory::getDbo();
	 
		/* Ein JDatabaseQuery Objekt beziehen */
		$query = $db->getQuery(true);
		
		$sqlstring = "INSERT INTO `#__anjolina` (`catid`) VALUES ";
		
		
		foreach ($ids as $id) {
			$sqlstring =  $sqlstring."('.$id.'),";
		}
		$sqlstring = substr($sqlstring, 0, strlen($sqlstring)-1).";";

		
		$db->setQuery($sqlstring);
		
		if($db->query()){
//			echo($query,"Erfolg Insert Query");
		}
		else{
//			echo($query,"Fail Insert Query");
		}	
		
		$this->setRedirect('index.php?option=com_anjolina');
	}
	
	
	public function mobile_unpublish()
	{
	
		
		$ids = JRequest::getVar('cid', array(), '', 'array');
		
		/* Ein Datenbankobjekt beziehen */
		$db = JFactory::getDbo();
	 
		/* Ein JDatabaseQuery Objekt beziehen */
		$query = $db->getQuery(true);
		
		
		foreach ($ids as $id) {
			$sqlstring =  "DELETE FROM `#__anjolina` WHERE `#__anjolina`.catid=".$id.";";
			

		
			$db->setQuery($sqlstring);
			
			if($db->query()){
//				echo($query,"Erfolg Delete Query ".$id);
			}
			else{
//				echo($query,"Fail Delete Query ".$id);
			}	
			
		}

		
		$this->setRedirect('index.php?option=com_anjolina');
	}
	
	
	
	
	public function plugin_unpublish()
	{
		$ids = JRequest::getVar('cid', array(), '', 'array');

		
		// Create a new query object.
		$db		= JFactory::getDbo();
		$query	= $db->getQuery(true);
		$user	= JFactory::getUser();

		
		$queryraw = 'UPDATE #__ajl_plugins SET activexml = 0 WHERE id='.$id;
		
		
		$sqlstring = $queryraw;
		
		foreach ($ids as $id) {
			$sqlstring =  $sqlstring.$id." or ";
		}
		$sqlstring = substr($sqlstring, 0, strlen($sqlstring)-4).";";
		
		
		$db->setQuery($sqlstring);
		$db->query();
		
		$this->setRedirect('index.php?option=com_anjolina&view=anjolinaplugins');
		
	}
	
	public function plugin_publish()
	{
		$ids = JRequest::getVar('cid', array(), '', 'array');		
		
		// Create a new query object.
		$db		= JFactory::getDbo();
		$query	= $db->getQuery(true);
		$user	= JFactory::getUser();


		$queryraw = 'UPDATE #__ajl_plugins SET activexml = 1 WHERE id='.$id;
		
		
		$sqlstring = $queryraw;
		
		foreach ($ids as $id) {
			$sqlstring =  $sqlstring.$id." or ";
		}
		$sqlstring = substr($sqlstring, 0, strlen($sqlstring)-4).";";
		
		$db->setQuery($sqlstring);
		$db->query();
		
		
		
		$this->setRedirect('index.php?option=com_anjolina&view=anjolinaplugins');
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
public function xml_unpublish()
	{
		$ids = JRequest::getVar('cid', array(), '', 'array');		
		
		// Create a new query object.
		$db		= JFactory::getDbo();
		$query	= $db->getQuery(true);
		$user	= JFactory::getUser();

		$queryraw = 'UPDATE #__ajl_plugins SET activexml = 0 WHERE id='.$id;
		
		
		$sqlstring = $queryraw;
		
		foreach ($ids as $id) {
			$sqlstring =  $sqlstring.$id." or ";
		}
		$sqlstring = substr($sqlstring, 0, strlen($sqlstring)-4).";";
		
		
		$db->setQuery($sqlstring);
		$db->query();
		
		$this->setRedirect('index.php?option=com_anjolina&view=anjolinaplugins');
	}
	
	public function xml_publish()
	{
		$ids = JRequest::getVar('cid', array(), '', 'array');
		
		
		// Create a new query object.
		$db		= JFactory::getDbo();
		$query	= $db->getQuery(true);
		$user	= JFactory::getUser();
		
		$queryraw = 'UPDATE #__ajl_plugins SET activexml = 1 WHERE id='.$id;
		
		
		$sqlstring = $queryraw;
		
		foreach ($ids as $id) {
			$sqlstring =  $sqlstring.$id." or ";
		}
		$sqlstring = substr($sqlstring, 0, strlen($sqlstring)-4).";";
		
		$db->setQuery($sqlstring);
		$db->query();
		
		$this->setRedirect('index.php?option=com_anjolina&view=anjolinaplugins');
	}
	
	
	public function json_unpublish()
	{
		$ids = JRequest::getVar('cid', array(), '', 'array');
		
		// Create a new query object.
		$db		= JFactory::getDbo();
		$query	= $db->getQuery(true);
		$user	= JFactory::getUser();

		$queryraw = 'UPDATE #__ajl_plugins SET activejson = 0 WHERE id='.$id;
		
		
		$sqlstring = $queryraw;
		
		foreach ($ids as $id) {
			$sqlstring =  $sqlstring.$id." or ";
		}
		$sqlstring = substr($sqlstring, 0, strlen($sqlstring)-4).";";
		
		
		$db->setQuery($sqlstring);
		$db->query();
		
		$this->setRedirect('index.php?option=com_anjolina&view=anjolinaplugins');
	}
	
	public function json_publish()
	{
		$ids = JRequest::getVar('cid', array(), '', 'array');
		
		
		// Create a new query object.
		$db		= JFactory::getDbo();
		$query	= $db->getQuery(true);
		$user	= JFactory::getUser();
		
		$queryraw = 'UPDATE #__ajl_plugins SET activejson = 1 WHERE id='.$id;
		
		
		$sqlstring = $queryraw;
		
		foreach ($ids as $id) {
			$sqlstring =  $sqlstring.$id." or ";
		}
		$sqlstring = substr($sqlstring, 0, strlen($sqlstring)-4).";";
		//dump($sqlstring);
		
		$db->setQuery($sqlstring);
		$db->query();
		
		$this->setRedirect('index.php?option=com_anjolina&view=anjolinaplugins');
	}
	
	public function soap_unpublish()
	{
		$ids = JRequest::getVar('cid', array(), '', 'array');
		
		
		// Create a new query object.
		$db		= JFactory::getDbo();
		$query	= $db->getQuery(true);
		$user	= JFactory::getUser();

		$queryraw = 'UPDATE #__ajl_plugins SET activesoap = 0 WHERE id='.$id;
		
		
		$sqlstring = $queryraw;
		
		foreach ($ids as $id) {
			$sqlstring =  $sqlstring.$id." or ";
		}
		$sqlstring = substr($sqlstring, 0, strlen($sqlstring)-4).";";
		//dump($sqlstring);
		
		
		$db->setQuery($sqlstring);
		$db->query();
		
		$this->setRedirect('index.php?option=com_anjolina&view=anjolinaplugins');
	}
	
	public function soap_publish()
	{
		$ids = JRequest::getVar('cid', array(), '', 'array');
		
		
		// Create a new query object.
		$db		= JFactory::getDbo();
		$query	= $db->getQuery(true);
		$user	= JFactory::getUser();
		
		$queryraw = 'UPDATE #__ajl_plugins SET activesoap = 1 WHERE id='.$id;
		
		
		$sqlstring = $queryraw;
		
		foreach ($ids as $id) {
			$sqlstring =  $sqlstring.$id." or ";
		}
		$sqlstring = substr($sqlstring, 0, strlen($sqlstring)-4).";";
		
		$db->setQuery($sqlstring);
		$db->query();
		
		$this->setRedirect('index.php?option=com_anjolina&view=anjolinaplugins');
	}
	
	
	public function deleteLog()
	{

		$fullpath = JPath::find(JPATH_ROOT  . DS . 'logs' . DS . 'anjolina', "com_anjolina.log.php");
		if($fullpath<>FALSE) {
			
			JFile::delete($fullpath);
			
		}
		else {
			//no log to delete
		}
		$this->setRedirect('index.php?option=com_anjolina&view=showlogs');
	}
	
	public function toCat()
	{
		$this->setRedirect('index.php?option=com_anjolina&view=selectcategories');
	}
	public function toPlug()
	{
		$this->setRedirect('index.php?option=com_anjolina&view=anjolinaplugins');
	}
	public function toLog()
	{
		$this->setRedirect('index.php?option=com_anjolina&view=showlogs');
	}
	
}